import 'package:jet_rails/jr_app/jr_models/jr_comment_model.dart';
import 'package:jet_rails/jr_app/jr_models/jr_user_model.dart';
import 'package:jet_rails/jr_utils/extensions/jr_list_extension.dart';
import 'package:json_annotation/json_annotation.dart';

part 'jr_activity_model.g.dart';

@JsonSerializable()
class JrActivityModel {
  String authorCode;
  JrUserModel? author;
  String? title;
  String? teamName;
  String? time;
  String? place;
  String? description;
  String? thumbnail;
  @JsonKey(name: 'content', defaultValue: [])
  List<String> content;
  bool likedByMe;
  bool joined;
  @JsonKey(name: 'commentList', defaultValue: [])
  List<JrCommentModel> commentList = [];
  int attendedUser;

  JrActivityModel(
      {required this.authorCode,
      this.author,
      required this.commentList,
      this.title,
      this.teamName,
      this.time,
      this.place,
      this.description,
      required this.content,
      this.thumbnail,
      this.likedByMe = false,
      this.joined = false,
      this.attendedUser = 0}) {
    teamName ??= title?.split(' ').safeLast;
  }

  factory JrActivityModel.fromJson(Map<String, dynamic> json) => _$JrActivityModelFromJson(json);

  Map<String, dynamic> toJson() => _$JrActivityModelToJson(this);
}
